<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<!--

/* SVN FILE: $Id: platform.html 18 2008-07-06 15:42:11Z rafaelbandeira3 $ */
/**
* Application : The Javascript MVC Framework
*
* @package application.core
* @subpackage cookie
* @author 			$Author: rafaelbandeira3 $
* @copyright 		(c) Rafael Bandeira, Marcelo Condotta, Henrique Condotta. All Rights Reserved.
* @version 			$Revision: 18 $
* @lastrevision 	$Date: 2008-07-06 15:42:11 +0000 (Sun, 06 Jul 2008) $
* @modifiedby 		$LastChangedBy: rafaelbandeira3 $
* @lastmodified 	$LastChangedDate: 2008-07-06 15:42:11 +0000 (Sun, 06 Jul 2008) $
* @license 			The MIT License [http://www.opensource.org/licenses/mit-license.php]
* @filesource 		$URL: http://jsmvcapplication.googlecode.com/svn/trunk/application/test/platform.html $
*/

-->
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link href="platform.css" rel="stylesheet" />
		
		<title>Application :: Unit Test Platform</title>
		<script type="text/javascript" src="../lib/prototype/prototype.js"></script>
		<script type="text/javascript" src="../lib/scriptaculous/unittest.js"></script>
		<script type="text/javascript">

			var TESTS_ROOT = String(window.location).replace(/\/platform.html.*/,'');
			var CASES_ROOT = TESTS_ROOT+'/cases';
			
			String.prototype.ucFirst = function()
			{
				uc = this.substr(0,1).toUpperCase();
				return this.replace(/./,uc);
			}
			
			var _containers = new Array();
			var getMenu = function(resource)
			{
				resource = resource.replace(/\/$/,'');
				if(!_containers.include(resource))
				{
					_containers.push(resource);
					new Ajax.Request(resource,
					{
						'method' : 'get',
						'onSuccess' : makeMenu.wrap(function(proceed, transport)
						{
							cont = new Element('DIV');
							cont.update(transport.responseText);
							links = cont.select('a');
							links = links.select(function(element){ return !element.search; });
							links = links.map(function(element)
							{
								if(!element.href.match(CASES_ROOT))
									element.href = element.href.replace(TESTS_ROOT,_containers[_containers.length-1]);
								return element;
							});
							proceed(links);
						})
					});
				}
				else 
					return 0;
			}
			var makeMenu = function(links)
			{
				tests = links.select(function(element){ return element.href.endsWith('.js'); });
				tests.each(function(element){ $('Menu').insert(parseMenuItem(element)); });

				containers = links.select(function(element){ return !element.href.match('.js'); });
				containers.each(function(element){ getMenu(element.href); });
			}
			var parseMenuItem = function(element)
			{
				casePath = element.href.replace(CASES_ROOT,'').replace('.js','').replace(/^\//,'');
				caseLink = new Element('A');
				caseLink.href = '?case='+casePath;
				caseLink.update(casePath.gsub(/\//,'.'));

				return (new Element('LI')).insert(caseLink);
			}

			if(window.location.search)
			{
				params = window.location.search.toQueryParams();
				if(params['case'])
				{
					_case = params['case'];

					scriptPath	= '../src/%.js'.replace('%',_case);
					testPath 	= 'cases/%.js'.replace('%',_case);

					tag = '<script type="text/javascript" src="%"> <\/script>';

					document.write(tag.replace('%',scriptPath));
					document.write(tag.replace('%',testPath));

					packageName = _case.replace('/','.').toLowerCase();
					
					title = packageName.split('.').invoke('ucFirst').reverse().join(' &raquo; ').unescapeHTML();
					document.title = '% &raquo; Application :: Unit Test Platform'.replace('%',title);
					
					document.observe('dom:loaded',function()
					{
						unit = packageName.split('.').last().camelize().ucFirst();
						unitTest = unit+'Test';
						
						$('TestCaseInfo').show();
						$('File').update(testPath.substr(6));
						$('Unit').update(unit);
						$('Test').update(unitTest);

						testCase = window[unitTest];
						
						if(testCase.initialize)
							testCase.initialize();
						
						new Test.Unit.Runner(testCase);
					});
				}
			}

			getMenu(CASES_ROOT);

		</script>
	</head>
	<body>
		
		
		<h1><a href="platform.html">Application Unit Test Platform</a></h1>
		<ul id="Menu">
			
		</ul>
		<p id="TestCaseInfo" style="display:none">
		  Test info: <br />
		  &raquo; file: <b id="File">%file</b><br />
		  &raquo; unit: <b id="Unit">%unit</b><br />
		  &raquo; test: <b id="Test">%testunit</b>
		</p>
		
		<!-- Log output -->
		<div id="testlog"></div>
		<div id="result"></div>
		
	</body>
</html>
